<?php 
   
    $cp = $_GET['cp'];
    
    //echo $cp;return;
    $con = mysql_connect("localhost","root","");
    mysql_select_db("joomviet", $con);
    $result = mysql_query("select * from hff_erp_cuppon where code_cuppon = '".$cp."' and used=0");
    $rs= mysql_fetch_array($result);
    
    if($rs==NULL)
    {
        echo "0";
        return;
    }
    /*
    jimport('joomla.application.component.model');
    $sql = "select * from hff_erp_cuppon where code_cuppon = '".$cp."' and id_product = '".$id."' and used=0";
                    $db = &JFactory::getDBO();
        		    $db->setQuery($sql);
                    $rs = $db->loadObject();
                    */
    /*$cup = array('id_cup' => $rs['id']
                       ,'id_product' =>$rs['id_product'] 
	                   ,'id_product_type' => $rs['id_product_type']
	                   ,'money' => $rs['money']
                       ,'persent' => $rs['persent']);
    echo json_encode($cup);*/
    
    if($rs['id_product'] != NULL && $rs['money'] != NULL)
    {
        $cup = array('id_cup' => $rs['id']
                       ,'id_product' =>$rs['id_product'] 
	                   ,'id_product_type' => $rs['id_product_type']
	                   ,'money' => $rs['money']
                       ,'persent' => $rs['persent']
                       ,'flag' => 1);
          echo json_encode($cup);
    return;
    }
    
    if($rs['id_product'] != NULL && $rs['persent'] != NULL)
    {
        $cup = array('id_cup' => $rs['id']
                       ,'id_product' =>$rs['id_product'] 
	                   ,'id_product_type' => $rs['id_product_type']
	                   ,'money' => $rs['money']
                       ,'persent' => $rs['persent']
                       ,'flag' => 2);
            echo json_encode($cup);
    return;
    }
    
    if($rs['id_product_type'] != NULL && $rs['money'] != NULL)
    {
        $cup = array('id_cup' => $rs['id']
                       ,'id_product' =>$rs['id_product'] 
	                   ,'id_product_type' => $rs['id_product_type']
	                   ,'money' => $rs['money']
                       ,'persent' => $rs['persent']
                       ,'flag' => 3);
            echo json_encode($cup);
    return;
    }
    
    if($rs['id_product_type'] != NULL && $rs['persent'] != NULL)
    {
        $cup = array('id_cup' => $rs['id']
                       ,'id_product' =>$rs['id_product'] 
	                   ,'id_product_type' => $rs['id_product_type']
	                   ,'money' => $rs['money']
                       ,'persent' => $rs['persent']
                       ,'flag' => 4);
            echo json_encode($cup);
    return;
    }
    
    
?>